#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Camera_2DComponent;
using Swarm_Defense;
#endregion

/* Frankly, this sucks as a component.  It implements the main menu, and isn't reusable or generic.
 * So I'm open to suggestions... :) 
 */
namespace MenuComponent
{
    #region MenuClasses
    public class MenuItem : Object_2D
    {
        protected Game1 _game;
        public MenuItem(string Name, Vector2 Loc, Texture2D Tex, Texture2D Tex_selected, int XsizeIn, int YsizeIn)
            : base (Name, Loc, Tex, Tex_selected, XsizeIn, YsizeIn)
        {
            this._zorder = ZORDER_ENUM.Z_MENUITEM;
            this._scalable = false;
        }
    }
    public class MenuBackground : Object_2D
    {
        private int _width;
        private int _height;

        public MenuBackground(string Name, Vector2 Loc, Texture2D Tex, int Height, int Width)
            : base (Name, Loc, Tex, Height, Width)
        {
            this._zorder = ZORDER_ENUM.Z_MENU;
            this._selectedTexture = null;
            this._scalable = true;
            this._height = Height;
            this._width = Width;
        }

        public override void Draw(SpriteBatch renderer)
        {
            renderer.Draw(_texture, new Rectangle(0, 0, _height, _width), Color.White);
        }
    }
    public class MenuGameStart : MenuItem
    {
        public MenuGameStart(string Name, Vector2 Loc, Texture2D Tex, Texture2D Tex_selected, Game1 MainObject, int XsizeIn, int YsizeIn)
            : base(Name, Loc, Tex, Tex_selected, XsizeIn, YsizeIn)
        {
            _game = MainObject;
        }
        public override void OnSelect()
        {
            _game.GameState = Game1.GAMESTATE_ENUM.GAME_RUNNING;
 	        base.OnSelect();
        }
    }
    public class MenuGameOptions : MenuItem
    {
        public MenuGameOptions(string Name, Vector2 Loc, Texture2D Tex, Texture2D Tex_selected, Game1 MainObject, int XsizeIn, int YsizeIn)
            : base(Name, Loc, Tex, Tex_selected, XsizeIn, YsizeIn)
        {
            _game = MainObject;
        }
        public override void OnSelect()
        {
            _game.GameState = Game1.GAMESTATE_ENUM.GAME_RUNNING;
            base.OnSelect();
        }
    }
    #endregion 
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    /// 
    public class Menu : Microsoft.Xna.Framework.DrawableGameComponent
    {
        public List<Object_2D> MenuItemList = new List<Object_2D>();
        private SpriteBatch _spriteBatch;

        ContentManager _content;
        private Game1 _game;

        public Menu(Game Game)
            : base(Game)
        {
            _game = (Game1)Game;
            _content = _game.content;
            // TODO: Construct any child components here
        }


        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here
            this.Enabled = true;
            this.Visible = false;
            base.Initialize();
        }

        protected override void LoadGraphicsContent(bool loadAllContent)
        {
            if (loadAllContent)
            {
                _spriteBatch = new SpriteBatch(GraphicsDevice);
            }
        }

        public void SetupMainMenu(int Height, int Width)
        {
            MenuBackground tempMenuItem = new MenuBackground("Background", new Vector2(0, 0), _content.Load<Texture2D>(@"Content\\Menu\\menu_background"),
                Height, Width);
            MenuItemList.Add(tempMenuItem);

            MenuGameStart tempGameStart = new MenuGameStart("Start", new Vector2(500, 400),
                        _content.Load<Texture2D>(@"Content\\Menu\\start"),
                        _content.Load<Texture2D>(@"Content\\Menu\\start_selected"),
                        _game,
                        100, 100);
            MenuItemList.Add(tempGameStart);


            MenuGameOptions tempGameOptions = new MenuGameOptions("Start", new Vector2(500, 500),
                        _content.Load<Texture2D>(@"Content\\Menu\\options"),
                        _content.Load<Texture2D>(@"Content\\Menu\\options_selected"),
                        _game, 100, 100);
            MenuItemList.Add(tempGameOptions);
        }
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime GameTime)
        {
            

            base.Update(GameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            _spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
            for (int i = 0; i < MenuItemList.Count; i++)
            {
                MenuItemList[i].Draw(_spriteBatch);
            }
            _spriteBatch.End();
            base.Draw(gameTime);

        }
    }
}


